package intranet.models;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Connection;

public class DetailFileModel {
	Connection DBConnection=null;
	public DetailFileModel(){
		DatabaseModel DBModel=new DatabaseModel();
		DBConnection=DBModel.GetConnection();
	}
	
	public ResultSet DetailFile(String str){
		int strx=Integer.parseInt(str);
		ResultSet rs=null;
		try{
			Statement ConStatement=DBConnection.createStatement();
			String sql="SELECT uf.FILE_ID,uf.FILE_TITLE,uf.FILE_SIZE,fc.CATEGORY_NAME,uf.FREQUENCY,DBMS_LOB.SUBSTR(uf.FILE_DESC,DBMS_LOB.GETLENGTH(uf.FILE_DESC),1) AS FILE_DESC,ua.USER_NAME,ug.group_NAME,uf.DATE_UPLOAD,fk.keyword FROM " +
					"UPLOADED_FILES uf " +
					"INNER JOIN FILE_ACCESSIBLE_USERS fau ON uf.FILE_ID=fau.FILE_ID " +
					"INNER JOIN USER_ACCOUNTS ua ON fau.USER_ID=ua.USER_ID " +
					"INNER JOIN FILE_ACCESSIBLE_GROUPS fag ON fag.FILE_ID=fau.FILE_ID " +
					"INNER JOIN USER_GROUPS ug ON ug.GROUP_ID=fag.GROUP_ID " +
					"INNER JOIN FILE_CATEGORIES fc ON uf.CATEGORY_ID=fc.CATEGORY_ID " +
					"INNER JOIN FILE_KEYWORDS fk ON fk.FILE_ID=uf.FILE_ID " +
					"INNER JOIN FILE_KEYWORDS ON uf.FILE_ID=uf.FILE_ID WHERE uf.FILE_ID="+strx+"";
			rs=ConStatement.executeQuery(sql);
		}catch(Exception ex){ex.getLocalizedMessage();}
return rs;
	}
	public ResultSet Uploader(String str){
		ResultSet rs=null;
		int strx=Integer.parseInt(str);
		try{
			Statement ConStatement=DBConnection.createStatement();
			String sql="SELECT ua.USER_NAME FROM  FILE_ACCESSIBLE_USERS fau " +
					"INNER JOIN UPLOADED_FILES uf ON fau.FILE_ID=uf.FILE_ID " +
					"INNER JOIN USER_ACCOUNTS ua ON uf.USER_UPLOAD=ua.USER_ID WHERE uf.USER_UPLOAD="+strx+"";
			rs=ConStatement.executeQuery(sql);
		}catch(Exception ex){ex.getLocalizedMessage();}
return rs;
	}
	
}
